package com.itita.ww2.game.worldmap.event;

import java.util.Iterator;
import java.util.Vector;

import com.itita.ww2.model.user.UserProfile;
import com.itita.ww2.model.worldmap.Base;
import com.itita.ww2.model.worldmap.City;
import com.itita.ww2.puredb.model.Alliance;
import com.itita.ww2.puredb.model.AllianceMember;

/**
 * 大地图事件分发
 * @author NorthLan
 *
 */
public class WorldMapEventDispatch {
	private static Vector<IWMCityDataUpdateListener> m_CityDataUpdateListeners = new Vector<>();
	private static Vector<IWMBaseDataUpdateListener> m_BaseDataUpdateListeners = new Vector<>();
	private static Vector<IWMCityUnderAttackListener> m_CityUnderAttackListeners = new Vector<>();
	private static Vector<IWMCityOccupiedListener> m_AlOccupiedCityListeners = new Vector<>();
	private static Vector<IWMCityDeclaredListener> m_CityDeclaredListeners = new Vector<>();
	//
	private static Vector<IWMAllBaseUpdateListener> m_AllBaseUpdateListeners = new Vector<>();
	private static Vector<IWMAllCityUpdateListener> m_AllCityUpdateListeners = new Vector<>();

	public static void addListener(IWMCityDataUpdateListener listener) {
		m_CityDataUpdateListeners.add(listener);
	}

	public static void addListener(IWMCityDeclaredListener listener) {
		m_CityDeclaredListeners.add(listener);
	}

	public static void addListener(IWMBaseDataUpdateListener listener) {
		m_BaseDataUpdateListeners.add(listener);
	}

	public static void addListener(IWMCityUnderAttackListener listener) {
		m_CityUnderAttackListeners.add(listener);
	}

	public static void addListener(IWMCityOccupiedListener listener) {
		m_AlOccupiedCityListeners.add(listener);
	}

	// 
	public static void addListener(IWMAllBaseUpdateListener listener) {
		m_AllBaseUpdateListeners.add(listener);
	}

	public static void addListener(IWMAllCityUpdateListener listener) {
		m_AllCityUpdateListeners.add(listener);
	}

	/**
	 * 所有城池数据更新触发器
	 */
	public static void onAllCityDataUpdate() {
		for (Iterator<IWMAllCityUpdateListener> iter = m_AllCityUpdateListeners.iterator(); iter.hasNext();) {
			iter.next().onAllCityUpdate();
		}
	}

	/**
	 * 据点数据更新触发器
	 */
	public static void onAllBaseDataUpdate(City city) {
		for (Iterator<IWMAllBaseUpdateListener> iter = m_AllBaseUpdateListeners.iterator(); iter.hasNext();) {
			iter.next().onAllBaseUpdate(city);
		}
	}

	/**
	 * 城池被宣战
	 */
	public static void onCityDeclared(City city, UserProfile source, Alliance sourceAlliance,
			AllianceMember sourceMember, String targetAid) {
		for (Iterator<IWMCityDeclaredListener> iter = m_CityDeclaredListeners.iterator(); iter.hasNext();) {
			iter.next().onCityDeclared(city, source, sourceAlliance, sourceMember, targetAid);
		}
	}

	/**
	 * 城池被占领
	 */
	public static void onCityOccupied(City city, UserProfile profile, String preOwnerAid) {
		for (Iterator<IWMCityOccupiedListener> iter = m_AlOccupiedCityListeners.iterator(); iter.hasNext();) {
			iter.next().onAllianceOccupiedCity(city, profile, preOwnerAid);
		}
	}

	/**
	 * 城池被攻击
	 */
	public static void onCityUnderAttack(City city, UserProfile profile) {
		for (Iterator<IWMCityUnderAttackListener> iter = m_CityUnderAttackListeners.iterator(); iter.hasNext();) {
			iter.next().onCityUnderAtk(city, profile);
		}
	}

	/**
	 * 城池数据更新触发器
	 */
	public static void onCityDataUpdate(City city) {
		for (Iterator<IWMCityDataUpdateListener> iter = m_CityDataUpdateListeners.iterator(); iter.hasNext();) {
			iter.next().onCityDataUpdate(city);
		}
	}

	/**
	 * 据点数据更新触发器
	 */
	public static void onBaseDataUpdate(Base base) {
		for (Iterator<IWMBaseDataUpdateListener> iter = m_BaseDataUpdateListeners.iterator(); iter.hasNext();) {
			iter.next().onBaseSimpleDataUpdate(base);
		}
	}
}
